package datasource;

import com.mchange.v2.c3p0.cfg.C3P0Config;
import homework.jdbc.domain.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
 * Created by Administrator on 2017/9/14.
 */
public class UserDao {
             public  int pageSize=3;
             public List<User> findPage(int page)throws SQLException{
                 Connection conn= C3P0Utils.getConnection();
                 List<User> list=new ArrayList<>();
                 String sql="select*from user order by uid asc limit";
                 PreparedStatement ps=conn.prepareStatement(sql);
                 ps.setInt(1,(page-1)*pageSize);
                 ps.setInt(2,pageSize);
                 ResultSet result =ps.executeQuery();
                 while ((result.next())){
                     User user=new User();
                     user.setUid(result.getInt(1));
                     user.setUsername(result.getString(2));
                     user.setPassword((result.getString(3)));
                     list.add(user);
                 }
                 return list;
             }

}
